package com.albaba.designpattern.state_pattern.text_003;

/**
 * @Description: 交通灯类
 * @Author zx
 * @Date 2025/2/25 15:42
 * @Version 1.0
 * 红灯(禁行) 黄灯(警示) 绿灯(通行)
 */
public class TrafficLight {

    // 初始化状态为红灯
    State state = new RedState();

    public void setState(State state) {
        this.state = state;
    }

    // 切换为绿灯,通行状态
    public void switchToGreen() {
        state.switchToGreen(this);
    }

    // 切换为黄灯,警示状态
    public void switchToYellow() {
        state.switchToYellow(this);
    }

    // 切换为红灯,禁行状态
    public void switchToRed() {
        state.switchToRed(this);
    }
}
